package libs.yzx.zaza.acts2;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import libs.yzx.zaza.util.PermissionUtil;

/**
 * Created by Administrator on 2016/9/13.
 */
public class PermissionActivity extends AppCompatActivity{

    final int requestCode = 999;
    private PermissionUtil.PermissionDealer pd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pd = PermissionUtil.with(this);

        pd.setListener(new PermissionUtil.OnPermissionRequestListener() {
            public void onGranted(int requestCode, String[] permissions) {
                Toast.makeText(PermissionActivity.this, "ok", Toast.LENGTH_SHORT).show();
            }
            public void onFailed(int requestCode, String[] permissions) {
                Toast.makeText(PermissionActivity.this, "failed", Toast.LENGTH_SHORT).show();
            }
        });
        pd.request(requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        pd.handleResult(requestCode,permissions,grantResults);
    }

}
